"""
Author： Mr.Sun
Datetime： 2023/3/27 11:18 
FileName: my_exception.py
Desc: 
"""
import sys
import traceback
from utils.logger import logger
from functools import wraps


def except_decorator(func):
    @wraps(func)
    def handle_except(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            exc_type, exc_instance, exc_traceback = sys.exc_info()
            formatted_traceback = ''.join(traceback.format_tb(exc_traceback))
            message = '\n{0}\n{1}:\n{2}'.format(
                formatted_traceback,
                exc_type.__name__,
                exc_instance
            )
            logger.error("function: " + str(func.__name__) + "() 的错误信息: " + str(e))
            return e
        finally:
            pass

    return handle_except
